import request from '@/utils/request'

/**
 * 初始化分片上传
 */
export function initUploadPart(params) {
  return request({
    url: '/common/initUploadPart',
    method: 'post',
    params: {
      fileName: params.fileName,
      size: params.size,
    }
  });
}

/**
 * 上传文件分片
 */
export function uploadFileChunk(url,uploadId, chunkNumber,file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/common/uploadChunk',
    method: 'post',
    params: {
      url,
      uploadId,
      chunkNumber
    },
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
      repeatSubmit: false
    }
  });
}

/**
 * 完成分片上传
 */
export function completeUpload(params) {
  const { chunkNumber, totalChunks, url, uploadId} = params;
  return request({
    url: '/common/completeUpload',
    method: 'post',
    params: {
      chunkNumber,
      totalChunks,
      url,
      uploadId
    }
  });
}
